package com.vecspace.dayu.code.model;

import com.google.common.base.CaseFormat;

public class SrcCodeUtils {
	/**根据字段名获取变量名
	 * 
	 * @param underscoreStr
	 * @return 
	 * @author wanghua
	 */
	public static String getVarName(String underscoreStr) {
		if(underscoreStr == null)return "";
		underscoreStr = underscoreStr.trim().toUpperCase();
		
		while(underscoreStr.startsWith("_")) underscoreStr = underscoreStr.substring(1);
		while(underscoreStr.endsWith("_")) underscoreStr = underscoreStr.substring(0, underscoreStr.length()-1);
		String varName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, underscoreStr);
		return varName;
	}
	
	/**根据字段名，获取首字母大写的变量名
	 * 
	 * @return 
	 * @author wanghua
	 */
	public static String getPropName(String underscoreStr) {
		if(underscoreStr == null)return "";
		underscoreStr = underscoreStr.trim().toUpperCase();
		
		while(underscoreStr.startsWith("_")) underscoreStr = underscoreStr.substring(1);
		while(underscoreStr.endsWith("_")) underscoreStr = underscoreStr.substring(0, underscoreStr.length()-1);
		String varName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, underscoreStr);
		return varName;
	}
}
